package Test_0205;

import java.util.*;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
public class Test {
    public static void main3(String[] args) {
        Map<String,Integer> map1=new HashMap<>();
        map1.put("a",3);
        map1.put("c",5);
        map1.put("c",3);
        map1.put("s",21);
        //Set<K> keySet：返回key中不重复的
        Set<String> keySet=map1.keySet();
        System.out.println(keySet);//[a, c, s]
        //Collection<V> values:返回value可重复的集合
        Collection<Integer> values=map1.values();
        System.out.println(values);//[3, 3, 21]
        Set<Map.Entry<String,Integer>> entrySet=map1.entrySet();
        System.out.println(entrySet);//[a=3, c=3, s=21]
    }
    public static void main(String[] args) {
        Map<String,Integer> map=new HashMap<>();
        //map：设置k,v值
        map.put("a",2);
        map.put("c",5);
        map.put("s",21);
        //get：获取key对应的value值
        System.out.println(map.get("a"));//2
        System.out.println(map.get("b"));//不存在key值，其默认值为null
        //getOrDefault：
        //如果map中有key值，返回key对应的value1值，否则返回设置的默认值
        System.out.println(map.getOrDefault("a",1));//2
        System.out.println(map.getOrDefault("b",3));//3
        //remove1：如果key值与指定的值相匹配，删除；否则，不删除
        map.remove("a",1);//不匹配不删除
        System.out.println(map.get("a"));//a对应的value还是2
        //remove2：删除key对应的value值
        map.remove("a");
        System.out.println(map.get("a"));//null
        //containsKey:判断是否包含key
        System.out.println(map.containsKey("c"));//true
        //containsValue:判断是否包含value值
        System.out.println(map.containsValue(10));//false
    }
    public static void main1(String[] args) {
        Map<String,Integer> map1=new HashMap<>();
        Map<String,Integer> map2=new TreeMap<>();
    }
}
